<HTML>
<HEAD>
<TITLE>Contributing changes with CVS</TITLE>
</HEAD>
<BODY>
<TABLE BORDER="0" CELLSPACING="1" CELLPADDING="3" BORDER="0" WIDTH="100%">
  <TR>
    <SPAN CLASS="Header">Contributing source code changes with command-line CVS</SPAN>
<P>
<SPAN CLASS="PlainText"><B>CVS tool documents: Index</B>
<P>
<UL>
<DL>
<DT><A HREF="ddCVS.html">About source code version control with CVS</A>
<DT><A HREF="ddCVS_cvsglossary.html">A version control glossary</A>
<DD><A HREF="ddUsingCVS_command-line.html">Using command-line CVS to access project source files</A>
<DD><B>You are here: Contributing source code changes with CVS
<UL>
	<LI><A HREF="#cvscommit">Committing files and directories</A>
	<LI><A HREF="#cvsadd">Adding new files and directories</A>
	<LI><A HREF="#work">Working with files</A>
	<LI><A HREF="#filetypes">About file types</A>
	<LI><A HREF="#cvsupdate">Keeping your working copy up to date (cvs update)</A>
	<LI><A HREF="#cvstatus">Comparing your working files to the CVS repository</A>
	<LI><A HREF="#otherdiff">Comparing files before you commit</A>
	<LI><A HREF="#cvsmerging">Merging your changes</A>
	<LI><A HREF="#cvsresolving">Resolving merge conflicts</A>
	<LI><A HREF="#reverting">Revision history and reverting</A>
</UL></B>
<DD><A HREF="ddCVS_cvsmanaging.html">Managing project files and directories with CVS</A>
<DT><A HREF="/servlets/HelpTOC">Back to main Help index</A>
</DL>
</UL>
<P>

<HR NOSHADE SIZE=1>
<SPAN CLASS="InputHeader"><A NAME="contributing"></A>Contributing your changes into CVS</SPAN>
<P>
<A NAME="cvscommit"></A>To <I>commit</I> your changes to a file into the shared repository, type:
<BLOCKQUOTE>
       <B>cvs commit -m "Type your changes message here" filename</B>
</BLOCKQUOTE>
<P>
If you do not include a description of your change to the file, you will be prompted to add it by invoking your file editor before CVS can complete the commit action. 
<P>
To commit your changes to all files in a directory and any subdirectories:
<BLOCKQUOTE>
          <B>cd top_directory_to_commit</B><BR>
          <B>cvs commit -m "Type your change message here"</B>
</BLOCKQUOTE>
<P>
All commits are logged automatically and posted to the project's cvs mailing list.
<P>
<HR NOSHADE SIZE=1>
<A NAME="cvsadd"></A><SPAN CLASS="InputHeader">Adding files/directories</SPAN>

        <P>To <I>add</I> a new file to the CVS repository after you have first created and edited it in your working directory, type:
<BLOCKQUOTE>
          <B>cvs add filename</B><BR>
</BLOCKQUOTE>
         Then follow up with the &quot;cvs commit filename&quot command. If you do not first add the file, CVS does not recognize it.</LI>

<P>
If you have cvs write permissions, you can add subdirectories to your project's source tree using the &quot<B>cvs add</B>&quot command. You can then move existing files into new subdirectories with the &quot;<B>cvs move</B>&quot; command.
<P>
<A HREF="http://cvsbook.red-bean.com/cvsbook.html#Committing" TARGET="_new">More about committing changes</A><BR>
<A HREF="http://cvshome.org/docs/manual/cvs_7.html#SEC66" TARGET="_new">More about adding files and directories</A>
<P>

<HR NOSHADE SIZE=1>
<SPAN CLASS="InputHeader"><A NAME="work"></A>Working with files</SPAN>
<P>
Between checking files out of the project repository and checking them back in, CVS has virtually nothing to do with how files are used in the project environment or build process. That is governed by the project owner and other external factors unique to the project.
<P>
When you make changes to existing files, you must edit your working copies of these files in a file editor on your local machine using your file editor of choice. None of the changes you make to your working files has any effect on the project's source repository or on other developers' work until you check in (that is, do a <I>cvs commit</I>) your modified versions of files.
<P>
More about "<A HREF="http://www.cvshome.org/docs/manual/cvs_1.html#SEC1" TARGET=_NEW>What CVS is not</A>."
<P>

<HR NOSHADE SIZE=1>
<SPAN CLASS="InputHeader"><A NAME="filetypes"></A>About file types</SPAN>
<P>
<P>
The information provided in this document about CVS commands and actions assumes that the project files you are working with are text files. It is possible to include binary files in version control with CVS, although there are some special issues.
<P>
More about <A HREF="http://cvshome.org/docs/manual/cvs_9.html#SEC80" TARGET="_new">Handling binary files</A> in CVS.
<P>

<HR NOSHADE SIZE=1>
<A NAME="cvsupdate"></A><SPAN CLASS="InputHeader">Keeping your working files up to date with the repository</SPAN>
<P>
If you want to look before you leap, you can get a list of all files in your local directory not up to date with the project repository by using the following command:<BR>
<BLOCKQUOTE>
          <B>cvs -qn update</B> </LI>
</BLOCKQUOTE>
Files in the affected directory or directories are listed with their current status indicated as follows:
<UL>
<LI>? = File is unrecognized by CVS (needs to be added and committed).
<LI>A = File is added; file is recognized by CVS but still needs to be committed to the repository.
<LI>M = File has been modified by another developer since you checked out your working copy. This means that you need to update.
<LI>U = File is updated.
<LI>C = File has merge conflicts that must be resolved by hand.
</UL>
<P>
To go ahead and actually perform an update to make your working directory up to sync with the repository, the command is:
<BLOCKQUOTE>
	<B>cvs update</B>
</BLOCKQUOTE>
You can also update individual files by adding the filename to the command.
<P>Or, to include any new directories when updating, do:
<BLOCKQUOTE>
        <B>cvs update -d</B> 
</BLOCKQUOTE>
<P> 
<A HREF="http://www.gnu.org/manual/cvs/html_chapter/cvs_20.html#SEC132" TARGET="_new">More about the cvs update command</A><BR>
<A HREF="http://www.gnu.org/manual/cvs/html_chapter/cvs_20.html#SEC134" TARGET="_new">More about CVS update output</A>
<P>

<HR NOSHADE SIZE=1>
<A NAME="cvstatus"></A><SPAN CLASS="InputHeader">Comparing your working files to the repository</SPAN>
<P>
Another way to determine whether all of your working files are in sync with the latest versions in the repository is with the command:
<BLOCKQUOTE>
<B>cvstatus</B><BR>
</BLOCKQUOTE>
or for status on individual files:<BR> 
<BLOCKQUOTE>
<B>cvs status filename</B>
</BLOCKQUOTE>
<P>
This comparison may return one of the following messages:
<P>
<dl>
 <dt><b>Locally Added</b></dt>
     <dd>You have added the file with `add', and not yet committed your
     changes.</dd>

	<dt><b>Locally Removed</b></dt>
     <dd>You have removed the file with `remove', and not yet committed
     your changes.</dd>

	<dt><b>Needs Checkout</b></dt>
     <dd>Someone else has committed a newer revision to the repository.
     The name is slightly misleading; you will ordinarily use `update'
     rather than `checkout' to get that newer revision.</dd>

   <dt><b>Needs Patch</b></dt>

   <dd>Like Needs Checkout, but the CVS server will send a patch rather
     than the entire file. Sending a patch or sending an entire file
     accomplishes the same thing.</dd>

   <dt><b>Needs Merge</b></dt>
     <dd>Someone else has committed a newer revision to the repository, and
     you have also made modifications to the file.</dd>

   <dt><b>File had conflicts on merge</b></dt>

   <dd>This is like Locally Modified, except that a previous `update'
     command gave a conflict and CVS could not resolve the changes made.  If you have not already done so, you need to open the file in an editor and <a href="ddCVS_cvscontributing.html#cvsresolving">resolve the conflict</a>.</dd>

   <dt><b>Unknown</b></dt>
     <dd>CVS doesn't know anything about this file.  For example, you have
     created a new file and have not run `cvs add'.</dd>
  </dl>


















<P>
In general, a good rule of thumb is to make sure your working files are up to date with the repository <I>just before you commit your changes to a file</I>. The reason for this is that sometimes your commit may be unsuccessful, for example, you may be trying to commit from the wrong directory or perhaps another developer has committed changes to that same file after you checked it out of the repository or last updated it. Trying to commit your changes to an older version of the same file often causes conflicts when CVS tries to merge these. The result of your commit attempt under such circumstances is a somewhat daunting failure message about "dying gasps" from CVS. (Unfortunately, you don't find this out until <I>after</I> you've gone through the process of mentally composing and entering a pithy change log message.)
<P>
To see the differences between your copy of a file and the latest version in the repository:<BR>
<BLOCKQUOTE>
          <B>cvs diff filename</B> </LI>
</BLOCKQUOTE>
<P>
<A HREF="http://cvsbook.red-bean.com/cvsbook.html#Finding_Out_What_You__And_Others__Did_--_update_And_diff" TARGET=_NEW>More about comparing your work with the project repository</A>
<P>

<HR NOSHADE SIZE=1>
<A NAME="diffs"></A><SPAN CLASS="InputHeader">Comparing versions of files <I>before</I> you commit (diff)</SPAN>
<P>
Perhaps you want to see the changes another developer has made to the same file <I>before</I> you commit your own changes. For example, suppose you are committing some very complex changes which you anticipate may conflict with another developer's work.
<P>
In this case, a workable solution is to save off your working file under a different name (something like: "filename-new"). Then you can run the &quot<B>cvs update</B>&quot command and compare the latest version from the repository with your file before committing your changes. You can even compare the two files side-by-side using the following diff command:
<BLOCKQUOTE>
<B>diff -y filename filename-new</B>
</BLOCKQUOTE>
<P>

<HR NOSHADE SIZE=1>
<A NAME="cvsmerging"></A><SPAN CLASS="InputHeader">Merging your changes with other developers' changes</SPAN>
<P>
By giving the &quot<B>cvs update</B>&quot command, you are essentially telling CVS to merge the latest versions of files from the repository into your working copies.
<P>
Sometimes, however, other modifications made to a file since you last updated do not mesh well with your version. Or, you've made changes that conflict with the repository version. CVS makes every attempt to resolve such conflicts automatically when you update and commit, but sometimes it cannot resolve everything. Conflicts within the file must be resolved by hand.
<P>

<HR NOSHADE SIZE=1>
<A NAME="cvsresolving"></A><SPAN CLASS="InputHeader">Resolving merge conflicts</SPAN>
<P>
To resolve merge conflicts, open the file in your file editor. Look for lines or sections marked by <B>>>>>>></B> and <B><<<<<<<</B>. When CVS cannot resolve a conflict, it includes both verions of the affected line or sections inthe file, with the latest version usually first. Your task is to delete the unwanted lines, along with the lines containing the conflict symbols and revisions numbers. Then you can save the file and commit again.

<P>
<A HREF="http://www.gnu.org/manual/cvs/html_chapter/cvs_7.html#SEC40" TARGET="_new">An example of a conflict</A><BR>
<A HREF="http://cvsbook.red-bean.com/cvsbook.html#Detecting_And_Resolving_Conflicts" TARGET="_new">More about resolving conflicts</A>
<P>

<HR NOSHADE SIZE=1>
<A NAME="reverting"></A><SPAN CLASS="InputHeader">Revision history and reverting</SPAN>
<P>
Beyond the usefulness of being able to review a file's modification history using the &quot<B>cvs log</B>&quot command, those earlier file revisions can actually be restored as the most current revision (that is, restored to the "repository head") by the process of <I>reverting</I>. This becomes a particularly useful option if you need to return to an earlier point in a file's evolution for whatever reason, somewhat like being able to turn back the clock. When development projects experience broken builds or other problems, this becomes one of the most useful and powerful features of version control.
<P>
A word of caution: it's easy to get confused by the terminology of "revisions" versus "versions." <I>Revisions</I> are specific updates to individual files, such  1.1, 1.2, 1.3. When you run the "cvs log filename" command, the results are all of that particular file's revision numbers. By contrast, <I>versions</I> are <B><I>sets</I></B> of file revisions that are tagged and named at a certain point in time. The confusion occurs because versions are sometimes named similarly to file revisions (1.0, 1.1, 1.2 etc.). But versions do not have to be named this way; they can be any set of characters the Project Owner designates, and probably should use a different numbering scheme.

<P>
First, before you attempting to do any reverting, it's recommended that you examine the differences between the file version currently at the head of the repository and the version you want to revert to. The command to do this is:
<BLOCKQUOTE>
<B>cvs diff -c -r version# -r version# filename</B>
</BLOCKQUOTE>
<P>
This enables you to compare the two files before attempting to revert. The order for the file versions in this command is not critical, as long as you know can distinguish between the two versions. 
<P>
The command to revert requires strict observance in ordering the version numbers, however. Assuming you want to revert from a later version to an earlier version, the command is:
<BLOCKQUOTE>
<B>cvs update -j later_version# -j earlier_version# filename</B>
</BLOCKQUOTE>
<P>
Because there is more than one method for reverting, see also:<BR>
<A HREF="http://cvsbook.red-bean.com/cvsbook.html#Examining_And_Reverting_Changes" TARGET="_new">More about reverting</A><BR>
<A HREF="http://www.gnu.org/manual/cvs/html_chapter/cvs_16.html#SEC72" TARGET="_new">More about revision history</A><BR>
<P>

You should also know that reverting may result in "sticky tag" errors. These can be resolved using the following update command with a special switch: 
<BLOCKQUOTE>
<B>cvs update -dAP</B>
</BLOCKQUOTE>
(<A H REF="http://cvsbook.red-bean.com/cvsbook.html#Getting_Snapshots__Dates_And_Tagging_" TARGET="_new">What are sticky tag errors?</A>)
<P>

<!--
<P>
<A NAME="cvstips"><span class="InputHeader">Feedback on this document</span></A>
<P>
The author of this help document has made every attempt to compile accurate, helpful information about using CVS for projects hosted on this site. If you think any content in the above document is wrong, inadequate, or something is just plain missing ... that's good. This is open source, so step up to the plate and contribute your suggestions for additions and improvements.
<P>
-->

<HR NOSHADE SIZE=1>
More CVS help: <A HREF="ddCVS_cvsmanaging.html">Managing project files and directories with command line CVS</A><BR>
<A HREF="/servlets/HelpTOC">Back to main Help index</A></P></SPAN>

</SPAN> 
</TR>
</TABLE>
</BODY>
</HTML>
